#include "widget.h"
#include "ui_widget.h"
#include<QDebug>
#include<QValidator>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    ui->pushButton_sumbit->setEnabled(false);

    ui->lineEdit_name->setPlaceholderText("请输入姓名");
    ui->lineEdit_name->setClearButtonEnabled(true);

    ui->lineEdit_password->setPlaceholderText("请输入密码");
    ui->lineEdit_name->setClearButtonEnabled(true);
    ui->lineEdit_password->setEchoMode(QLineEdit::Password);

    QRegExpValidator* r=new QRegExpValidator(QRegExp("^1\\d{10}$"));//正则表达式检验
    ui->lineEdit_phone->setValidator(r);

}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_sumbit_clicked()
{
    QString gender;
    if(ui->radioButton_male->isChecked())gender="男";
    else gender="女";
    qDebug()<<ui->lineEdit_name->text()
            <<ui->lineEdit_phone->text()
            <<gender
            <<ui->lineEdit_password->text();
}

void Widget::on_lineEdit_phone_textEdited(const QString &arg1)
{
        //(void)arg1;
        //qDebug()<<arg1;
        QString content=arg1;
        int pos=0;
        if(ui->lineEdit_phone->validator()->validate(content,pos)== QValidator::Acceptable){
            ui->pushButton_sumbit->setEnabled(true);
        }
        else {
            ui->pushButton_sumbit->setEnabled(false);
        }
}
